package algorithm;

import java.util.ArrayList;
import java.util.Comparator;
import java.util.List;

public class Leetcode179 {

    public String largestNumber(int[] nums) {
        List<String> list = new ArrayList<>();
        for (int num : nums) {
            list.add(String.valueOf(num));
        }
        list.sort(new Comparator<String>() {
            @Override
            public int compare(String o1, String o2) {
                String str1 = o1+o2;
                String str2 = o2+o1;
                return str2.compareTo(str1);
            }
        });

        StringBuilder builder = new StringBuilder();
        for (String str : list) {
            builder.append(str);
        }
        if (builder.charAt(0) == '0') {
            return "0";
        }
        return builder.toString();
    }
}
